#ifndef _WEBSOCKET_PROTOCOL_H_
#define _WEBSOCKET_PROTOCOL_H_


#include <web_socket.h>
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <cJSON.h>

#define WEBSOCKET_PROTOCOL_SERVER_HELLO_EVENT (1 << 0)

class WebsocketProtocol {
public:
    WebsocketProtocol();
    ~WebsocketProtocol();

    // 发送audio
    void SendAudio(const std::vector<uint8_t>& data);
    // 发送text
    void SendText(const std::string& text);

    // 注册接收到json回调
    void OnIncomingJson(std::function<void(const cJSON* root)> callback);
    // open socket
    bool OpenAudioChannel();
    // close socket
    void CloseAudioChannel();

    bool IsAudioChannelOpened() const;

    std::function<void(const cJSON* root)> on_incoming_json_;

private:
    EventGroupHandle_t event_group_handle_;
    WebSocket* websocket_ = nullptr;
};

#endif
